package com.atguigu.yygh.common.util;

import com.atguigu.yygh.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * @FileName: AuthContextHolder
 * @Author Steven
 * @Date: 2021/8/10
 */
public class AuthContextHolder {
    /**
     * token获取当前登录用户ID
     * @param request
     * @return 当前用户ID
     */
    public static long getUserId(HttpServletRequest request){
        //从header中获取token
        String token = request.getHeader("token");
        //从token中获取用户ID
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    /**
     * token中获取当前用户名字
     * @param request
     * @return 当前用户名称
     */
    public static String getUserName(HttpServletRequest request){
        //从header中获取token
        String token = request.getHeader("token");
        String userName = JwtHelper.getUserName(token);
        return userName;
    }

}
